package com.wtc.smallchangesys;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class SmallChangeSys {
    public static void main(String[] args) {
        //1.零钱通菜单界面
        boolean loop = true;
        double balance = 0;
        Date date = null;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd  HH:mm");
        String details = "";
        Scanner scanner = new Scanner(System.in);
        do {
            System.out.println("----------------零钱通-----------------");
            System.out.println("\t\t\t\t\t\t1  零钱通明细");
            System.out.println("\t\t\t\t\t\t2  收 益 入 账");
            System.out.println("\t\t\t\t\t\t3  消            费");
            System.out.println("\t\t\t\t\t\t4  退            出");
            System.out.println("---------------------------------------");
            System.out.print("请输入相应选项的序号(1-4)：");
            int key = scanner.nextInt();
            switch (key) {
                case 1:
                    System.out.println("---------------零钱通明细--------------");
                    System.out.println(details);
                    break;
                case 2:
                    System.out.print(" 请输入入账金额：");
                    double money = scanner.nextDouble();
                    if (money <= 0) {
                        System.out.println("收益金额需大于零！");
                        break;
                    }
                    balance += money;
                    date = new Date();
                    details += "收益入账:\t+" + money + "\t\t" + simpleDateFormat.format(date) + "\t\t余额:" + balance + "\n";
                    break;
                case 3:
                    System.out.print(" 请输入消费金额：");
                    money = scanner.nextInt();
                    System.out.print(" 请输入消费信息：");
                    String note = scanner.next();
                    if (money <= 0 || money > balance) {
                        System.out.println("消费金额需大于零且不能大于余额！");
                    }
                    balance -= money;
                    date = new Date();
                    details += note + ":\t-" + money + "\t\t" + simpleDateFormat.format(date) + "\t\t余额:" + balance + "\n";
                    break;
                case 4:
                    String choice = "";
                    while (true) {
                        System.out.print("你确定要退出系统吗？y/n");
                        choice = scanner.next();
                        if ("y".equals(choice) || "n".equals(choice)) {
                            break;
                        }
                    }
                    if (choice.equals("y")) {
                        loop = false;
                    }
                    System.out.println("---------------系统退出----------------");
                    break;
                default:
                    System.out.println("你输入的不是序号或者序号有误！请重新输入！");
            }
        } while (loop);
    }
}
